﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace SharpShare.Storage.FileSystem {
    public class FileStorageFile : FileStorageItem, IStorageFile {
        public FileStorageFile(FileInfo info, IFileStorageItemFactory factory)
            : base(info, factory) {

        }

        public new FileInfo Info { get { return (FileInfo)((FileStorageItem)this).Info; } }

        protected override void Move(string newPath) {
            this.Info.MoveTo(newPath);
        }

        #region IStorageFile Members

        public long Length {
            get {
                try {
                    this.DemandExists();
                    return this.Info.Length;
                } catch (StorageException) {
                    throw;
                } catch (Exception ex) {
                    throw HandleException(ex, ExceptionAttemptedAction.ReadAttributes);
                }
            }
        }

        public IStorageDataProvider Open(StorageFileAccess access, StorageFileAccess share) {
            try {
                return new FileDataProvider(this, access, share);
            } catch (StorageException) {
                throw;
            } catch (Exception ex) {
                throw HandleException(ex, ExceptionAttemptedAction.Open);
            }
        }

        #endregion
    }
}
